<?php
/*echo "<script language='JavaScript'>
alert('1');
 </script>";*/

//if ($_GET['page']=="form") {

	$TxtNama 	= $_POST['nama'];
	$TxtAlamat	= $_POST['alamat'];
	$TxtEmail	= $_POST['email'];
	$RbKelamin 	= $_POST['kelamin'];
	$SlctUsia	= $_POST['usia'];
	$TxtAgama	= $_POST['agama'];
	$SlctPend	= $_POST['pend'];
	$SlctProdi	= $_POST['prodi'];
	$TxtarKemp	= $_POST['kemp'];
	$SlctPosisi	= $_POST['posisi'];
	$TxtKtp	    = $_POST['ktp'];
	$TxtIjasah  = $_POST['ijasah'];

	
	if (trim($_POST['nama']) =="") {
		$pesan[] = "Data Nama masih kosong";
	}
	if (trim($_POST['alamat']) =="") {
		$pesan[] = "Data Alamat masih kosong";
	}
	if (trim($_POST['email']) =="") {
		$pesan[] = "Data Email masih kosong";
	}
	if (trim($_POST['kelamin']) =="") {
		$pesan[] = "Data Jenis Kelamin belum dipilih";
		$_POST['kelamin']=="P";
	}
	if (trim($_POST['usia']) =="") {
		$pesan[] =  "Data Usia masih kosong";
	}
	if (trim($_POST['agama']) =="") {
		$pesan[] = "Data Agama masih kosong";
	}
	if (trim($_POST['pend']) =="") {
		$pesan[] = "Data Pendidikan belum dipilih";
	}
	if (trim($_POST['prodi']) =="") {
		$pesan[] = "Data Program Studi belum dipilih";
	}
	if (trim($_POST['kemp']) =="") {
		$pesan[] = "Data Kemampuan Penunjang masih kosong";
	}
	if (trim($_POST['posisi']) =="") {
		$pesan[] = "Data Posisi belum dipilih";
	}
	if (trim($_POST['ktp']) =="" OR
	! is_numeric(trim($_POST['ktp']))) {
		$pesan[] = "Data Nomor KTP masih kosong, harus angka";
		$_POST['ktp'] = "";
	}
	if (trim($_POST['ijasah']) =="" OR
	! is_numeric(trim($_POST['ijasah']))) {
		$pesan[] = "Data Nomor Ijasah masih kosong, harus angka";
		$_POST['ijasah'] = "";
	}

	/*echo "<script language='JavaScript'>
	alert('".
	$TxtNama 	.
	$TxtAlamat	.
	$TxtEmail	.
	$RbKelamin  .
	$SlctUsia	.
	$TxtAgama	.
	$SlctPend	.
	$SlctProdi  .
	$TxtarKemp	.
	$SlctPosisi .
	$TxtKtp	    .
	$TxtIjasah  .
	"');
	 </script>";*/
	
	/*	 	if (trim($_POST['TxtPost']) =="" OR
	 ! is_numeric(trim($_POST['TxtPost']))) {
	$pesan[] = "Data Kode Post masih kosong, harus angka";
	$_POST['TxtPost'] = "";
	}

	if (trim($_POST['TxtNoTelp']) =="" OR
	! is_numeric(trim($_POST['TxtNoTelp']))) {
	$pesan[] = "Data No Telepon masih kosong, harus angka";
	$_POST['TxtNoTelp'] = "";
	}
	if (trim($_POST['TxtNoHp']) =="" OR
	! is_numeric(trim($_POST['TxtNoHp']))) {
	$pesan[] = "Data No HP masih kosong, harus angka";
	$_POST['TxtNoHp'] = "";
	}
	/* 	if (trim($_POST['NamaFile']) =="") {
	$pesan[] = "Data File masih kosong";
	}
	if (trim($_POST['TxtUserId']) =="") {
	$pesan[] = "Data User ID masih kosong";
	}
	if (trim($_POST['TxtPassId']) =="") {
	$pesan[] = "Data Password masih kosong";
	} */

	//if (! count($pesan)==0 ) {
	
		include_once "../librari/koneksi.php";
		include_once "librari/librari.php";

	/*	echo "<script language='JavaScript'>
				alert('test');
				 </script>";
*/

		//$kode= kdauto("pelamar");
		$sql = "INSERT INTO pelamar SET 
				nama = '".$TxtNama."',
				email= '".$TxtEmail."',
				alamat= '".$TxtAlamat."',
				kelamin= '".$RbKelamin."',
				usia='".$SlctUsia."',
				agama= '".$TxtAgama."',
				pendTerakhir='".$SlctPend."',
				prodi='".$SlctProdi."',
				kempenunjang= '".$TxtarKemp."',
				posisi= '".$SlctPosisi."',
				noKtp='".$TxtKtp."',
				noIjasah='".$TxtIjasah."'";

		
		//echo $sql;
		mysql_query($sql)
		or die ("Gagal query simpan".mysql_error());

		//$FileName = $_FILES['NamaFile']['name'];

		//$FileName = stripslashes($FileName);
		//$FileName = str_replace("'","",$FileName);
		//copy($_FILES['NamaFile']['tmp_name'],"images/KTP/".$FileName);


		//Sukses
		//include "index.php";
		//echo "<meta http-equiv='refresh' content='daftarok'>";
		echo "<script language='JavaScript'>document.location='index.php';
		alert('Sukses. Klik OK!'); </script>";
	



?>

